#pragma comment(linker, "/STACK:10000000")
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <set>
#include <map>
#include <cstdio>
#include <cassert>
#include <string>
#include <cstring>
#define ldb long double
#define LL long long
#define fi first
#define se second
#define fill(a, c) memset(a, c, sizeof(a))
#define sqr(a) ((a) * (a))
#define nextLine() {int c = 0; while((c = getchar()) != 10 && c != EOF);}
#define getBit(mask, k) (((mask) / pw[k]) % pw[1])
#define setBit(mask, k, l) (((mask) / pw[k + 1] * pw[1] + (l)) * pw[k] + ((mask) % pw[k]))
#define debug(a) cerr << #a << " = " << a << " ";
#define debugl(a) cerr << #a << " = " << a << "\n";
#define mp(a, b) make_pair(a, b)
#define pb(a) push_back(a)
#define ff first
#define ss second 
const ldb LDINF = 9128739847123.00;
const ldb eps = 1e-9;
const int inf = 1 << 28;
const ldb pi = fabsl(atan2l(0.0, -1.0));
using namespace std;


const int mod = 1000000007;

int x[123], y[123];
int n, m;

void load()
{
	cin >> n >> m;
	for (int i = 0; i < m; i++)
	{
		cin >> x[i] >> y[i];
	}
}

int dp[123][123];
int s[123][123];

void solve()
{
	memset(dp, -1, sizeof dp);
	for (int i = 0; i <= n; i++)
		s[0][i] = 1;
	for (int i = 1; i <= m; i++)
	{
		for (int j = 0; j <= n; j++)
		{
			dp[i][j] = 0;
			if (j - x[i - 1] >= 0)
				dp[i][j] += s[i - 1][j - x[i - 1]];
			if (j - y[i - 1] - 1 >= 0)
				dp[i][j] -= s[i - 1][j - y[i - 1] - 1];
			if (dp[i][j] >= mod) dp[i][j] -= mod;
			while (dp[i][j] < 0) dp[i][j] += mod;
			s[i][j] = (j > 0 ? s[i][j - 1] : 0) + dp[i][j];
			if (s[i][j] >= mod) s[i][j] -= mod;
		}
	}
	cout << dp[m][n] << "\n";
}

#define file "dish"
int main()
{
	#ifndef ONLINE_JUDGE
		freopen(file".in", "rt", stdin);
		freopen(file".out", "wt", stdout);
	#endif
	int T;
	cin >> T;
	for (int i = 0; i < T; i++)
	{
		load(); solve();
	}
	return 0;
}
